package com.deli.springboot;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class BeanUtilsDemo {
    public static void main(String[] args) {
//        User user = new User();
//        Target target = new Target();
//        Field[] fields = user.getClass().getDeclaredFields();
//        Field[] fields1 = target.getClass().getFields();
//        for (Field userField : fields) {
//            for (Field targetField : fields1) {
//                if(userField.getName().equalsIgnoreCase("serialVersionUID")){
//
//                }
//            }
//        }
    }

    private static void copyUtils(Object resoure,Object target){
        Field[] resoureFields = resoure.getClass().getDeclaredFields();
        Field[] targetFields = target.getClass().getDeclaredFields();
        for (Field resoureField : resoureFields) {
            for (Field targetField : targetFields) {
                if(resoureField.getName().equalsIgnoreCase("serialVersionUID")){
                    continue;
                }
                if (resoureField.getName().equalsIgnoreCase(targetField.getName())){
                    try {
                        Object o = resoure.getClass().getMethod("get" + toUpperFirst(resoureField.getName()), null).invoke(resoure, null);

                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    private static String toUpperFirst(String name) {
        if(null!=name||""!=name){
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.setCharAt(0,Character.toUpperCase(stringBuffer.charAt(0)));
            return stringBuffer.toString();
        }
        return null;
    }
}
